package com.hangsu.train.components.web.controller;

import com.hangsu.train.components.entity.Wanded;
import com.hangsu.train.components.params.IdParam;
import com.hangsu.train.components.params.WandedSearchParam;
import com.hangsu.train.components.service.WandedService;
import com.hangsu.train.core.result.Resp;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lyy
 * @Date 2024/11/17
 */
@Slf4j
@RestController
@RequestMapping("/wanded")
public class WandedController {

    @Resource
    private WandedService wandedService;

    /**
     * 伤票列表带翻页
     *
     * @param param
     * @return
     */
    @PostMapping("/list")
    public Resp<Page<Wanded>> list(@RequestBody @Valid WandedSearchParam param) {
        Page<Wanded> page = wandedService.list(param);
        return Resp.ok(page);
    }

    /**
     * 伤票列表带翻页
     *
     * @param param
     * @return
     */
    @PostMapping("/search")
    public Resp<List<Wanded>> search(@RequestBody @Valid WandedSearchParam param) {
        List<Wanded> list = wandedService.search(param);
        return Resp.ok(list);
    }

    /**
     * 伤票列表带翻页
     *
     * @param param
     * @return
     */
    @PostMapping("/save")
    public Resp<Long> save(@RequestBody @Valid Wanded param) {
        long id = wandedService.save(param);
        return Resp.ok(id);
    }

    @PostMapping("/update")
    public Resp<Long> update(@RequestBody @Valid Wanded param) {
        wandedService.update(param);
        return Resp.ok();
    }

    /**
     * 伤票详情
     *
     * @param param
     * @return
     */
    @PostMapping("/info")
    public Resp<Wanded> info(@RequestBody @Valid IdParam param) {
        Wanded wanded = wandedService.detail(param);
        return Resp.ok(wanded);
    }

    /**
     * 删除
     *
     * @param param
     * @return
     */
    @PostMapping("/del")
    public Resp<Void> del(@RequestBody @Valid IdParam param) {
        wandedService.del(param);
        return Resp.ok();
    }

}
